package com.gsbelarus.gedemin.salary.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.gsbelarus.gedemin.salary.R;
import com.gsbelarus.gedemin.salary.entity.DrawerPersonInfoItem;

import java.util.ArrayList;
import java.util.List;

public class DrawerPersonInfoAdapter extends RecyclerView.Adapter<DrawerPersonInfoAdapter.ViewHolder> {

    private List<DrawerPersonInfoItem> items;

    public DrawerPersonInfoAdapter(Context context) {
        items = new ArrayList<>();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.drawer_person_info_list_item, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final DrawerPersonInfoItem item = items.get(position);

        holder.personInfoText.setText(item.getPersonInfoText());
        holder.personInfoItem.setText(item.getPersonInfoItem());
        holder.personInfoImage.setImageResource(item.getPersonInfoImage());
    }

    @Override
    public int getItemCount() {
        return items.size();
    }


    public DrawerPersonInfoAdapter add(DrawerPersonInfoItem item) {
        int position = items.size();
        items.add(position, item);
        notifyItemInserted(position);
        return this;
    }

    public void clear() {
        items.clear();
        notifyDataSetChanged();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView personInfoText;
        public TextView personInfoItem;
        public ImageView personInfoImage;

        public ViewHolder(View itemView) {
            super(itemView);
            personInfoText = (TextView) itemView.findViewById(R.id.person_info_text);
            personInfoItem = (TextView) itemView.findViewById(R.id.person_info_item);
            personInfoImage = (ImageView) itemView.findViewById(R.id.person_info_image);
        }
    }
}